class Solution(object):
    def minSubArrayLen(self, target, nums):
        """
        :type target: int
        :type nums: List[int]
        :rtype: int
        """
        l = 0
        min_len = len(nums) + 1
        total_sum = 0
        for r in range(len(nums)):
            total_sum += nums[r]
            #满足条件时则l右移，缩小窗口大小
            while total_sum >= target:
                min_len = min(min_len, r - l + 1)
                total_sum -= nums[l]
                l += 1
        return 0 if min_len > len(nums) else min_len
